package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.parameter.DisableDistributorBean;
import com.shop2cn.iapi.member.service.DisableDistributorCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.utils.TestDataManager;
/**
*接受交易禁用分销员消息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DisableDistributor{
	private static DisableDistributorBean disabledistributorBean;
	private static DisableDistributorCall disabledistributorCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("接受交易禁用分销员消息");
	}

	@Before
	public void caseUp() {
		disabledistributorBean=new DisableDistributorBean();
		disabledistributorCall=new DisableDistributorCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(disabledistributorCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DisableDistributor_001() {
		Logger.start(true,"接受交易禁用分销员消息成功");
		try {
			Integer shopid=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean dusercreateBean = DGUserCallService.initUsercreateBean();
			dusercreateBean.setShopId(shopid);
			dusercreateBean.setMobile(mobile);
			dusercreateBean.setUserType(3);
			Integer duserId = DGUserCallService.UserCreateCall(dusercreateBean);
			//2个userid 创建了2个会员 一个h5 一个小程序 使用同一个手机号绑定 在支付查询的时候需要按场景(h5 小程序)返回对应的openid
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			//60.小程序 61.h5
			createMem.setAccessSource(0);
			String mid = GodMemberService.creatememberCall(createMem);
			Integer csid=1;
			GodMemberService.bindMobile(shopid, userId, mobile,csid);
			disabledistributorBean.setDsId(duserId);
			disabledistributorBean.setShopId(shopid);
			disabledistributorCall.setData(disabledistributorBean);
			disabledistributorCall.callService();			
			Logger.verifyEquals("ok", disabledistributorCall.getReturnData(), "验证返回");
			Logger.verifyEquals(0, GodMemberService.briefmemberinfoCall(disabledistributorBean.getShopId(), userId).getDsId(), "验证dsid");
	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DisableDistributor_002() {
		Logger.start(true,"dsid存在H5和App2个,一起重置为0");
		try {
			Integer shopid=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean dusercreateBean = DGUserCallService.initUsercreateBean();
			dusercreateBean.setShopId(shopid);
			dusercreateBean.setMobile(mobile);
			dusercreateBean.setUserType(3);
			Integer duserId = DGUserCallService.UserCreateCall(dusercreateBean);
			//2个userid 创建了2个会员 一个h5 一个小程序 使用同一个手机号绑定 在支付查询的时候需要按场景(h5 小程序)返回对应的openid
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			UserCreateBean usercreateBean2= DGUserCallService.initUsercreateBean();
			int userId2=DGUserCallService.UserCreateCall(usercreateBean2);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			//60.小程序 61.h5
			createMem.setAccessSource(0);
			String mid = GodMemberService.creatememberCall(createMem);
			
			CreateMemberBean createMem2 = GodMemberService.initCreateMemberBean(shopid,userId2,usercreateBean2.getOpenId());
			//60.小程序 61.h5
			createMem2.setAccessSource(1);
			String mid2 = GodMemberService.creatememberCall(createMem2);
			Integer csid=1;
			GodMemberService.bindMobile(shopid, userId, mobile,1);
			GodMemberService.bindMobile(shopid, userId2, mobile);
			
			disabledistributorBean.setDsId(duserId);
			disabledistributorBean.setShopId(shopid);
			disabledistributorCall.setData(disabledistributorBean);
			disabledistributorCall.callService();			
			Logger.verifyEquals("ok", disabledistributorCall.getReturnData(), "验证返回");
			Logger.verifyEquals(0, GodMemberService.briefmemberinfoCall(disabledistributorBean.getShopId(), userId).getDsId(), "验证dsid");
			Logger.verifyEquals(0, GodMemberService.briefmemberinfoCall(disabledistributorBean.getShopId(), userId2).getDsId(), "验证dsid");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DisableDistributor_003() {
		Logger.start(true,"不输入shopid不处理");
		try {
			Integer shopid=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean dusercreateBean = DGUserCallService.initUsercreateBean();
			dusercreateBean.setShopId(shopid);
			dusercreateBean.setMobile(mobile);
			dusercreateBean.setUserType(3);
			Integer duserId = DGUserCallService.UserCreateCall(dusercreateBean);
			//2个userid 创建了2个会员 一个h5 一个小程序 使用同一个手机号绑定 在支付查询的时候需要按场景(h5 小程序)返回对应的openid
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			//60.小程序 61.h5
			createMem.setAccessSource(0);
			String mid = GodMemberService.creatememberCall(createMem);
			Integer csid=1;
			GodMemberService.bindMobile(shopid, userId, mobile,csid);
			disabledistributorBean.setDsId(duserId);
//			disabledistributorBean.setShopId(shopid);
			disabledistributorCall.setData(disabledistributorBean);
			disabledistributorCall.callService();			
			Logger.verifyEquals("ok", disabledistributorCall.getReturnData(), "验证返回");
			Logger.verifyEquals(duserId, GodMemberService.briefmemberinfoCall(shopid, userId).getDsId(), "验证dsid");

			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DisableDistributor_004() {
		Logger.start(true,"不输入dsid不处理");
		try {
			Integer shopid=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean dusercreateBean = DGUserCallService.initUsercreateBean();
			dusercreateBean.setShopId(shopid);
			dusercreateBean.setMobile(mobile);
			dusercreateBean.setUserType(3);
			Integer duserId = DGUserCallService.UserCreateCall(dusercreateBean);
			//2个userid 创建了2个会员 一个h5 一个小程序 使用同一个手机号绑定 在支付查询的时候需要按场景(h5 小程序)返回对应的openid
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			//60.小程序 61.h5
			createMem.setAccessSource(0);
			String mid = GodMemberService.creatememberCall(createMem);
			Integer csid=1;
			GodMemberService.bindMobile(shopid, userId, mobile,csid);
//			disabledistributorBean.setDsId(duserId);
			disabledistributorBean.setShopId(shopid);
			disabledistributorCall.setData(disabledistributorBean);
			disabledistributorCall.callService();			
			Logger.verifyEquals("ok", disabledistributorCall.getReturnData(), "验证返回");
			Logger.verifyEquals(duserId, GodMemberService.briefmemberinfoCall(shopid, userId).getDsId(), "验证dsid");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}